<?php
/*登录模块
 *author 王建
 *time 2013-04-17
 *
 */
if (! defined('BASEPATH')) {
	exit('Access Denied');
}

class Login extends CI_Controller {
    function Login(){
        parent::__construct();
        $this->load->model('admin/M_login');
		$this->load->library('session');//加载session
		$this->load->library('admin_common');//加载admin的公用方法
    }
    function show_login(){
    	$this->load->view('admin/login');
    }
    //function 处理登录页面
    function do_login(){
    	$post_data = $this->input->post(NULL,true) ;
    	$username =  $this->admin_common->do_addslashes($post_data['username']);
    	$passwd = $this->admin_common->do_addslashes($post_data['passwd']);
		
    	if(empty($username)){
    		showmessage('用户名错误请正确输入','admin/login/show_login',3,0) ;
    	}elseif(empty($passwd)){
    		showmessage('请输入正确的密码','admin/login/show_login',3,0) ;
    	}
    	$passwd =md5($post_data['passwd']);
    	$sql ="SELECT * FROM common_member where username='{$username}' and passwd='{$passwd}' AND allowadmin='1' AND status = '1'";
    	$result = $this->M_login->query_one($sql);
    	if(empty($result)){
    		showmessage('用户名或者密码错误','admin/login/show_login',3,0) ;
    	}else{
			$data_array =array(
				'username'=>$result['username'] ,
			);
			$this->session->set_userdata($data_array);
			
			header("Location:".site_url('admin/index/frame'));
    	}
       }
	 //login out
	 function login_out(){
		if($this->session->userdata('username')){
			$this->session->unset_userdata('username');
			showmessage('退出成功','admin/login/show_login',3,1) ;
		}
	 }
}